import { action } from 'mobx';

import ListBaseStore from './ListBaseStore';
import * as ItemApprovalApis from '../apis/itemApproval';
import * as ItemMonitorApis from '../apis/itemMonitor';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

/**
 * 主题审批Store
 */
export default class ItemApprovalStore extends ListBaseStore {
	constructor() {
		super();
		this.title = getLabel(32574, '主题审批');
	}

	@action doInit = () => {
    this.doBaseInit();
    this.initConditionDatas(); // 初始化高级搜索区域
    this.doTableLoading(); // 初始化列表
	}

	// 加载列表数据
	@action doTableLoading = (params) => {
		this.showLoading(true);

		let resultParams = this.getFormParams();
		let commonParams = {
			from: 'cowork',
			fromPage: 'itemApproval',
			layout: 2,
			jointype: 5,
		};
		resultParams = { ...resultParams, ...commonParams, ...params };

		ItemApprovalApis.getCoworkList(resultParams).then(
			(result) => {
				const sessionkey = result.sessionkey;
				this.sessionkey = sessionkey;
				this.comsWeaTableStore.getDatas(sessionkey, 1);

				this.showLoading(false);
			},
		);
	}

	// 初始化收藏的帖子页面查询条件
	@action initConditionDatas = (params) => {
		ItemApprovalApis.getCoworkItemApproveShareCondition(params).then(
			(result) => {
				this.conditioninfo = result.conditioninfo;

				this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
			},
		);
	}

	// 批准、批量批准
	@action batchCoworkItemApprove = (params, callback) => {
		ItemApprovalApis.batchCoworkItemApprove(params).then(
			() => {
				if (callback && typeof callback === 'function') {
					callback();
				}
			},
		);
	}

	// 删除、批量删除
	@action batchItemApprovalDelete = (params, callback) => {
		ItemMonitorApis.batchCoworkItemMonitorDel(params).then(
			() => {
				if (callback && typeof callback === 'function') {
					callback();
				}
			},
		);
	}
}
